package com.xncoding.ThreadLocal;

import java.util.HashMap;

public class ThreadLocalDemo {
    private static ThreadLocal<Integer> countLocal = new ThreadLocal<Integer>(){
        public Integer initialValue() {
            return 0;
        }
    };

    private static ThreadLocal<HashMap> countLocalMap = new ThreadLocal<HashMap>(){
        public HashMap initialValue() {
            return new HashMap();
        }
    };

    public static void main(String[] args){
        for (int i = 1; i <= 5; i++) {
            new Thread("Thread_" + i) {
                public void run() {
                    for (int j = 1; j <= 10; j++) {
                        countLocal.set(countLocal.get() + 1);
                        System.out.println(getName() + ": count=" + countLocal.get());
//                        countLocalMap.set(getName(),countLocal.get());
                    }
                };
            }.start();
        }
    }
}
